using BattleFury.Data;
using BattleFury.Lib;
using BattleFury.Lib.Collections;
using BattleFury.Lib.Network;
using BattleFury.Screens;
using Microsoft.Xna.Framework.Graphics;

namespace BattleFury
{
	public class BattleFuryClient
	{
		private readonly RenderEngine _engine;

		public BattleFuryClient()
		{
			_engine = RenderEngine.Get();
		}

		public void Configure(ClientConfiguration Config)
		{
			_engine.ChangeResolution(1280, 720);
			_engine.IsMouseVisible = true;
			_engine.Window.Title = "Battle Fury";
			_engine.NetworkEnabled = true;
			_engine.AppIdentifier = "Fury";
			_engine.Host = "localhost";
			_engine.Port = 28657;

			RenderData.SetConfig(Config);
			RenderData.Players = new PlayerCollection();
			RenderData.Bots = new BotCollection();

			_engine.LoadAdditionalContent += LoadInitialContent;
			_engine.AfterInitializeScreens += InitializeScreens;
		}

		private void LoadInitialContent(object sender, object e)
		{
			RenderData.Fonts.Add("Default", ((RenderEngine)sender).Content.Load<SpriteFont>(".\\gfx\\fonts\\default"));
		}

		public void InitializeScreens(object sender, object e)
		{
			var engine = (RenderEngine) sender;
			engine.Screens.Add(ScreenNames.Test, new TestScreen());
			engine.Screens.Change(ScreenNames.Test);

			//((RenderEngine)sender).Screens.Add(ScreenNames.Gameplay, new GameplayScreen());
			//((RenderEngine)sender).Screens.Change(ScreenNames.Gameplay);
		}

		internal void Run()
		{
			_engine.Run();
		}
	}
}